<%@page import="support.*, java.util.*, java.sql.*" %>

<%@page import="support.*, java.util.*" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Degree - Choose Discipline</title>
</head>
<body>
    <!-- Book keeping for degree -->
    <%
    // add the location to our current degree hashset
      String university = request.getParameter("university");
      LinkedHashSet<String> currentDegree = (LinkedHashSet<String>)session.getAttribute("currentDegree");
      currentDegree.add(university);
      // iterator to help go through the list
      Iterator it = currentDegree.iterator();
    %>

    Your college in <%= it.next() %> is: <%= it.next() %> <br>
    What is your Discipline? <br> <br>
    
    <%
    // Connect to Database
    try {
        Class.forName("org.postgresql.Driver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    
    // connect to local host 8082
    Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:8082/CSE135?" + "user=postgres&password=postgres");
    // create SQL statement
    Statement stmt = conn.createStatement();
    %>
    
    <%
    // use sql statement to display all the disciplines
    ResultSet rset = stmt.executeQuery("SELECT * FROM disciplines");
    %>  
    
    <!-- List of disciplines radio boxes -->
    <form method="GET" action= "moredegrees.jsp">

        <%
        // set default button
        if(rset.next()){
            out.print("<input type=\"radio\" name=\"discipline\" value=\"" +
                    rset.getString(1) + "\" ");
            out.print("checked>" + rset.getString(1) + "<br>");
        }
        // loop through majors vector
        while(rset.next()){
            out.print("<input type=\"radio\" name=\"discipline\" value=\"" +
                        rset.getString(1) + "\" ");
            out.print(">" + rset.getString(1) + "<br>");
        }
        // other option
        out.print("<input type=\"radio\" name=\"discipline\" value=\"other\">Other:");
        %>
        
    <!-- Text box for unorthodox major -->
    <input type="text" size="20" name="otherdiscipline" maxlength="20"/><br>
    
    <!-- Month and year the degree was awarded -->
    When was the Degree Awarded: <br>
    Month:  <input type="text" size="12" name="monthAwarded" maxlength="12">
    Year: <input type="text" size="6" name="yearAwarded" maxlength="5"> <br>
   
    <!-- GPA -->
    GPA: <input type="text" size="5" name="gpa" maxlength="5"> <br>
    
    <!-- Title degree of dropdown menu -->
    <select name="title"> 
        <option value="BS">BS</option>
        <option value="MS">MS</option>
        <option value="PhD">PhD</option>
    </select> <br>
    
    <!-- Obligatory submit button -->
    <input type=submit name="Submit"/>
    </form>
</body>
</html>